home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / laserjetii.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  3KB  |  145 lines

  1. /* This file contains the Laser Jet II device dependent subroutines for */
  2. /* use with plplot. Only the 150 dpi mode is supported.  The others     */
  3. /* (75,100,300) should work by just changing the value of DPI and       */
  4. /* changing the values passed to setphy in DEVICE.f77                   */
  5.  
  6. #include "plplot.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <math.h>
  11.  
  12. #define DPI      150            /* Resolution Dots per Inch */
  13. #define CURX     51
  14. #define CURY     61
  15. #define ESC      0x1b
  16. #define FF       0x0c
  17. #define XDOTS    1104           /* # dots across */
  18. #define YDOTS    1410           /* # dots down   */
  19. #define BPROW    XDOTS/8        /* # bytes across */
  20. #define NBYTES   BPROW*YDOTS    /* total number of bytes */
  21.  
  22. static FILE *OutFile;
  23.  
  24. /* bitmap contains a pointer to an area of memory NBYTES in size */
  25. static char *bitmap;
  26. static int FirstClear=1;
  27.  
  28. /* Opens the file for binary mode. */
  29.  
  30. void jetini()
  31. {
  32.   char FileName[80];
  33.  
  34.   printf("Enter file name for LaserJet II graphics commands. ");
  35.   scanf("%s",FileName);
  36.  
  37.   if((OutFile = fopen(FileName,"w")) == NULL) {
  38.    printf("Error opening %s \n",FileName);
  39.    exit(1);
  40.   }
  41.  
  42.   /* Allocate storage for bit map matrix */
  43.   if((bitmap = (char *)calloc(NBYTES,sizeof(char))) == NULL)
  44.    printf("Out of memory in call to calloc \n");
  45.  
  46.   /* Reset Printer */
  47.   fprintf(OutFile,"%cE",ESC);
  48. }
  49.  
  50. /* Set JET to test mode */
  51. void jettex()
  52. {
  53.   /* do nothing here */
  54. }
  55.  
  56. /* Set JET to graphics mode */
  57. void jetgra()
  58. {
  59.   /* Do nothing here */
  60. }
  61.  
  62. /* Print out page */
  63. void jetclr()
  64. {
  65.   int i,j;
  66.  
  67.   if(FirstClear)
  68.     FirstClear=0;
  69.   else {
  70.     /* First move cursor to origin */
  71.     fprintf(OutFile,"%c*p%dX",ESC,CURX);
  72.     fprintf(OutFile,"%c*p%dY",ESC,CURY);
  73.  
  74.     /* Then put Laser Printer in 150 dpi mode */
  75.     fprintf(OutFile,"%c*t%dR",ESC,DPI);
  76.     fprintf(OutFile,"%c*r1A",ESC);
  77.  
  78.     /* Write out raster data */
  79.     for(j=0;j<YDOTS;j++){
  80.       fprintf(OutFile,"%c*b%dW",ESC,BPROW);
  81.       for(i=0;i<BPROW;i++)
  82.         putc(*(bitmap+i+j*BPROW),OutFile);
  83.     }
  84.  
  85.     /* End raster graphics and send Form Feed */
  86.     fprintf(OutFile,"%c*rB",ESC);
  87.     fprintf(OutFile,"%c",FF);
  88.  
  89.     /* Finally, clear out bitmap storage area */
  90.     memset(bitmap,'\0',NBYTES);
  91.   }
  92. }
  93.  
  94. /* Change color */
  95. void jetcol(colour)
  96. int colour;
  97. {
  98. }
  99.  
  100. /* Function to draw the line in the bitmap */
  101. void jetlin(x1,y1,x2,y2)
  102. int x1,y1,x2,y2;
  103. {
  104.  int i;
  105.  float length,fx,fy,dx,dy;
  106.  void setpoint();
  107.  
  108.  length = (float)sqrt((double)((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
  109.  if(length == 0.)
  110.    length = 1.;
  111.  dx = (x2 - x1)/length;
  112.  dy = (y2 - y1)/length;
  113.  
  114.  fx = x1;
  115.  fy = y1;
  116.  setpoint(x1,y1);
  117.  setpoint(x2,y2);
  118.  
  119.  for(i=1;i<=(int)length;i++)
  120.   setpoint((int)(fx+=dx),(int)(fy+=dy));
  121. }
  122.  
  123. static char mask[8] = {'\200','\100','\040','\020','\010','\004','\002','\001'};
  124.  
  125. /* Function to set a bit in the bitmap */
  126. static void setpoint(x,y)
  127. int x,y;
  128. {
  129.  int index;
  130.  index = x/8 + y*BPROW;
  131.  *(bitmap+index) = *(bitmap+index) | mask[x%8];
  132. }
  133.  
  134. /* Reset printer and close file */
  135. void jettid()
  136. {
  137.   jetclr();
  138.   /* Reset Printer */
  139.   fprintf(OutFile,"%cE",ESC);
  140.   fclose(OutFile);
  141.   free((void *)bitmap);
  142. }
  143.  
  144.  
  145.